local Msg = require("core.Msg")
local FuliDefine = require("fuli.FuliDefine")
local Grid = require("bag.Grid")
local ExchangeLogic = require("fuli.ExchangeLogic")

local record = {}

function CG_FULI_SEE_ALL_RECORD(human)
  local sendMsg = Msg.gc.GC_FULI_COWRY_ALL_RECORD
  sendMsg.record[0] = #record
  local cache = {}
  for i=1, #record do
    sendMsg.record[i].name = record[i].name
    sendMsg.record[i].uuid = record[i].uuid
    Grid.create(cache, record[i].id, record[i].cnt, record[i].bind)
    Grid.makeItem(cache, sendMsg.record[i].item, 0, human)
  end
  Msg.send(sendMsg, human.fd)
end


function LW_FULI_SET_RECORD(human, msg)
  local len = math.min(#record, FuliDefine.FIND_COWRY_MAX_SELF_RECORD - 1)
  for i=len, 1, -1 do
    record[i + 1] = record[i]
  end

  record[1] = {}
  record[1].name = msg.name
  record[1].uuid = msg.uuid
  record[1].id = msg.id
  record[1].cnt = msg.cnt
  record[1].bind = msg.bind
end

function CG_FULI_EXCHANGE(human, msg)
  ExchangeLogic.exchange(human, msg.card)
end